<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-island-scenic__isscenicticket">
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
      >
        <el-form-item>
          <el-input
            v-model="dataForm.scenicName"
            placeholder="景区名称"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <SelectComponent
            v-model="dataForm.sort"
            placeholder="价格升序"
            :options="options"
          >
          </SelectComponent>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.ticketName"
            placeholder="票价名称"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <SelectComponent
            v-model="dataForm.ticketType"
            placeholder="门票类型"
            :options="ticketTypeOptions"
          >
          </SelectComponent>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t("query") }}</el-button>
        </el-form-item>
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        @selection-change="dataListSelectionChangeHandle"
        style="width: 100%"
      >
        <el-table-column
          type="selection"
          header-align="center"
          align="center"
          width="50"
        ></el-table-column>
         <el-table-column prop="id" label="编号" header-align="center" align="center"></el-table-column>
        <el-table-column
          prop="ticketName"
          label="票价名称"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="scenicName"
          label="景区名称"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="ticketTypeName"
          label="门票类型"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="realPrice"
          label="实际价格"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="discountPrice"
          label="折扣价格"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          :label="$t('handle')"
          fixed="right"
          header-align="center"
          align="center"
          width="150"
        >
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="viewHandle(scope.row)"
              >景点详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle"
      >
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update
        v-if="addOrUpdateVisible"
        ref="addOrUpdate"
        @refreshDataList="getDataList"
        @changeDisabled="disabled = false"
        :disabled="disabled"
      ></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
import AddOrUpdate from "./isscenicticket-add-or-update";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      disabled: false,
      ticketTypeOptions: [
        { dictValue: 1, dictLabel: "成人票" },
        { dictValue: 2, dictLabel: "优惠票" },
        { dictValue: 3, dictLabel: "儿童票" },
      ],
      options: [
        { dictValue: 0, dictLabel: "降序" },
        { dictValue: 1, dictLabel: "升序" },
      ],
      mixinViewModuleOptions: {
        getDataListURL: "/scenic/isscenicticket/page",
        getDataListIsPage: true,
      },
      dataForm: {
        scenicName:'',
        sort:'',
        ticketName:'',
        ticketType:'',
      },
    };
  },
  watch: {},
  components: {
    AddOrUpdate,
  },
  methods: {
     query() {
      this.dataListLoading = true
      this.$http.get(
        this.mixinViewModuleOptions.getDataListURL,
        {
          params: {
            order: this.order,
            orderField: this.orderField,
            page: this.mixinViewModuleOptions.getDataListIsPage ? this.page : null,
            limit: this.mixinViewModuleOptions.getDataListIsPage ? this.limit : null,
            ...this.dataForm
          }
        }
      ).then(({ data: res }) => {
        this.dataListLoading = false
        if (res.code !== 0) {
          this.dataList = []
          this.total = 0
          return this.$message.error(res.msg)
        }
        this.dataList = this.mixinViewModuleOptions.getDataListIsPage ? res.data.ticketList : res.data
        this.total = this.mixinViewModuleOptions.getDataListIsPage ? res.data.total : 0
      }).catch(() => {
        this.dataListLoading = false
      })
    },
    viewHandle(row) {
      this.addOrUpdateVisible = true;
      this.disabled = true;
      this.$nextTick(() => {
        this.$refs.addOrUpdate.visible = true;
        this.$refs.addOrUpdate.dataForm.id = row.scenicSpotId;
        this.$refs.addOrUpdate.init();
      });
    },
  },
};
</script>
